<%-- 
    Document   : denuncias
    Created on : 2/07/2013, 09:20:15 AM
    Author     : Luis Angel
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Locale"%>
<%@page import="java.util.Date"%>
<%@page import="yd2.edushare.Historial"%>
<%@page language="java" import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <% String _id_usuario = (String) session.getAttribute("id_usuario");
       int _id_articulo = Integer.parseInt(request.getParameter("id_articulo"));
       String _nombre_articulo = request.getParameter("nombre_articulo");
       if (_id_usuario != null) {
    %>
	<meta charset="utf-8">
	<title>EduShare - Denuncias</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
	<meta name="author" content="Muhammad Usman">

	<!-- The styles -->
	<link id="bs-css" href="css/bootstrap-cerulean.css" rel="stylesheet">
	<style type="text/css">
	  body {
		padding-bottom: 40px;
	  }
	  .sidebar-nav {
		padding: 9px 0;
	  }
	</style>
	<link href="css/bootstrap-responsive.css" rel="stylesheet">
	<link href="css/charisma-app.css" rel="stylesheet">
	<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
	<link href='css/fullcalendar.css' rel='stylesheet'>
	<link href='css/fullcalendar.print.css' rel='stylesheet'  media='print'>
	<link href='css/chosen.css' rel='stylesheet'>
	<link href='css/uniform.default.css' rel='stylesheet'>
	<link href='css/colorbox.css' rel='stylesheet'>
	<link href='css/jquery.cleditor.css' rel='stylesheet'>
	<link href='css/jquery.noty.css' rel='stylesheet'>
	<link href='css/noty_theme_default.css' rel='stylesheet'>
	<link href='css/elfinder.min.css' rel='stylesheet'>
	<link href='css/elfinder.theme.css' rel='stylesheet'>
	<link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
	<link href='css/opa-icons.css' rel='stylesheet'>
	<link href='css/uploadify.css' rel='stylesheet'>

	<!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
	<!--[if lt IE 9]>
	  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->

	<!-- The fav icon -->
	<link rel="shortcut icon" href="img/favicon.ico">
		
</head>

<body>
		<!-- topbar starts -->
	<div class="navbar">
		<div class="navbar-inner">
			<div class="container-fluid">
				<a class="btn btn-navbar" data-toggle="collapse" data-target=".top-nav.nav-collapse,.sidebar-nav.nav-collapse">
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</a>
				<a class="brand" href="index.html"> <img alt="Charisma Logo" src="img/logo20.png" /> <span>Edushare</span></a>
				
				
				<!-- user dropdown starts -->
                    <div class="btn-group pull-right" >

                        <%
                            String correoUsuario = null;
                            //si hay una sesion activa
                            if (session != null && session.getAttribute("correo") != null) {

                                //tomar el valor del correo del usuario
                                correoUsuario = session.getAttribute("correo").toString();
                                //colocar el html para mostra el usuario y el dropdown
                        %>
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="icon-user"></i><span class="hidden-phone"><%= correoUsuario%></span>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="perfil.jsp">Perfil</a></li>
                            <li class="divider"></li>
                            <li><a href="index.jsp?cs=true">Logout</a></li>
                        </ul>
                        <%} //si no hay una session activa
                        else {%>
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="login.jsp">
                            <i class="icon-user"></i><span class="hidden-phone">Login/Registro</span>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="login.jsp">Login</a></li>                            
                        </ul>
                        <%}%>
                    </div>
				
			</div>
		</div>
	</div>
	<!-- topbar ends -->
		<div class="container-fluid">
		<div class="row-fluid">
			
			<!-- left menu starts -->
			<div class="span2 main-menu-span">
                        <%--No se necesita el menu, sin embargo si el espacio--%>
			</div><!--/span-->
			<!-- left menu ends -->
			
			<noscript>
				<div class="alert alert-block span10">
					<h4 class="alert-heading">Atención!</h4>
					<p>You need to have <a href="http://es.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a> enabled to use this site.</p>
				</div>
			</noscript>
			
			<div id="content" class="span10">
			<!-- content starts -->
			

			<div>
				<ul class="breadcrumb">
					<li>
						<a href="#">Inicio</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="#">Ver Artículo</a> <span class="divider">/</span>
					</li>
                                        <li>
						<a href="#">Denuncias</a>
					</li>
				</ul>
			</div>
			
			<div class="row-fluid sortable">
				<div class="box span12">
					<div class="box-header well" data-original-title>
						<h2><i class="icon-edit"></i> Denunciar Artículos</h2>
						<div class="box-icon">
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						</div>
					</div>
					<div class="box-content">
						<form class="form-horizontal">
						  <fieldset>
                                                      <legend>¿Por qué no te ha parecido el artículo <% out.write(_nombre_articulo);  %>?</legend>
							<div class="control-group error">
								<label class="control-label" for="inputMotivo">Motivo de la denuncia:</label>
                                                            <div class="controls">
                                                              <select id="selectRazon" name="motivo" data-rel="chosen">
                                                                    <option>Falta de moral</option>
                                                                    <option>Información falsa</option>
                                                                    <option>Derechos de autor</option>
                                                                    <option>Pornografía</option>
                                                                    <option>Otros</option>
                                                              </select>
                                                            </div>
							</div>
                                                        <div class="control-group">
								<label class="control-label" for="disabledInput">Fecha:</label>
								<div class="controls">
								  <input class="input-xlarge disabled" id="disabledInput" type="text" placeholder="<%
                                                                    SimpleDateFormat formateador = new SimpleDateFormat("MM/dd/yyyy", new Locale("en_EN"));
                                                                    Date d=new Date();
                                                                    String fecha = formateador.format(d);
                                                                    out.write(fecha);
                                                                   %>" disabled="">
								</div>
							  </div>
                                                        <script type="text/javascript">
                                                            //Funciones para validar el máximo de caracteres en un textarea
                                                            function limita(elEvento, maximoCaracteres) {
                                                              var elemento = document.getElementById("texto");

                                                              // Obtener la tecla pulsada 
                                                              var evento = elEvento || window.event;
                                                              var codigoCaracter = evento.charCode || evento.keyCode;
                                                              // Permitir utilizar las teclas con flecha horizontal
                                                              if(codigoCaracter == 37 || codigoCaracter == 39) {
                                                                return true;
                                                              }

                                                              // Permitir borrar con la tecla Backspace y con la tecla Supr.
                                                              if(codigoCaracter == 8 || codigoCaracter == 46) {
                                                                return true;
                                                              }
                                                              else if(elemento.value.length >= maximoCaracteres ) {
                                                                return false;
                                                              }
                                                              else {
                                                                return true;
                                                              }
                                                            }

                                                            function actualizaInfo(maximoCaracteres) {
                                                              var elemento = document.getElementById("texto");
                                                              var info = document.getElementById("info");

                                                              if(elemento.value.length >= maximoCaracteres ) {
                                                                info.innerHTML = "Máximo "+maximoCaracteres+" caracteres";
                                                              }
                                                              else {
                                                                info.innerHTML = "Puedes escribir hasta "+(maximoCaracteres-elemento.value.length)+" caracteres adicionales";
                                                              }
                                                            }

                                                        </script>
                                                        <label class="control-label" for="textDenuncia">Justifique su denuncia:</label>
							<div class="controls">
                                                          <textarea id="texto" name="txtdenuncia" onkeypress="return limita(event, 300);" onkeyup="actualizaInfo(300)" rows="5" cols="50"></textarea>
							  <div id="info">Máximo 300 caracteres</div>
							</div>
							<div class="form-actions">
                                                            <button type="sumbit" name="denunciar" value="denunciar" class="btn btn-primary">Denunciar</button>
							  <button type="reset" class="btn">Cancelar</button>
                                                        </div>
                                                        <input type="hidden" name="id_articulo" value="<%out.write(String.valueOf(_id_articulo));%>" />
                                                        <input type="hidden" name="nombre_articulo" value="<%out.write(_nombre_articulo);%>" />
                                                        <%
                                                            if (request.getParameter("denunciar") != null){
                                                                //creamos la conexion
                                                                String user = "root";
                                                                String clave = "123";
                                                                String ruta = "jdbc:mysql://10.0.0.4/ayd2bd";
                                                                Connection conexion = null;
                                                                Statement Sentencias = null;
                                                                Statement Sentenc = null;
                                                                Statement Sent = null;
                                                                ResultSet tabla = null;
                                                                try {
                                                                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                                                                    conexion = DriverManager.getConnection(ruta, user, clave);
                                                                    Sentencias = conexion.createStatement();
                                                                } catch (Exception e) {
                                                                    out.println("<script>alert('Error de Conexion')</script>");
                                                                    e.printStackTrace();
                                                                }
                                                                //obtenemos todos los parametros
                                                                String rezon_d = request.getParameter("motivo");
                                                                String denuncias = request.getParameter("txtdenuncia");
                                                                int razon = 0;
                                                                if(rezon_d.equals("Falta de moral")) razon = 1;
                                                                if(rezon_d.equals("Información falsa")) razon = 2;
                                                                if(rezon_d.equals("Derechos de autor")) razon = 3;
                                                                if(rezon_d.equals("Pornografía")) razon = 4;
                                                                if(rezon_d.equals("Otros")) razon = 5;
                                                                Date dNow = new Date();
                                                                String HoraFecha;
                                                                SimpleDateFormat ft =
                                                                        new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                                                                String currentDate = ft.format(dNow);
                                                                HoraFecha = currentDate; //OBTENGO FECHA 
                                                                //query para insertar en denuncias
                                                                String queryInsert = "INSERT INTO DENUNCIA(id_usuario,id_articulo,fecha_hora,justificacion,id_razon_denuncia)"
 +                                                                                   "VALUES('"+_id_usuario+"','"+_id_articulo+"','"+HoraFecha+"','"+denuncias+"',"+razon+"',)";
                                                                Sentencias.executeQuery(queryInsert);
                                                                //Obtenemos la anterior ponderación
                                                                Sentenc = conexion.createStatement();
                                                                String queryGet = "SELECT punteo FROM PONDERACION WHERE id_articulo='"+_id_articulo+"'";
                                                                ResultSet dato = Sentenc.executeQuery(queryGet);
                                                                String pond = "";
                                                                
                                                                while (dato.next()) {
                                                                    pond = dato.getString("punteo");
                                                                    break;
                                                                }
                                                                //cambiamos su ponderación
                                                                int nuevo = Integer.getInteger(pond) - 5;
                                                                pond = String.valueOf(nuevo);
                                                                //Actualizamos los datos
                                                                Sent = conexion.createStatement();
                                                                String queryUpdate = "UPDATE PONDERACION SET punteo='"+pond+"' WHERE id_articulo='"+_id_articulo+"'";
                                                                Sent.executeQuery(queryUpdate);
                                                                //por ultimo guardamos el historial
                                                                Historial.guardarEntrada(6, "El usuario " +_id_usuario+"hizo una denuncia al articulo con id "+ _id_articulo, Integer.parseInt(_id_usuario));
                                                                out.println("<script>window.location = \"index.jsp\" </script>");
                                                            }
                                                            
                                                        %>
						  </fieldset>
						</form>   

					</div>
				</div><!--/span-->
			</div><!--/row-->
		<hr>

		<div class="modal hide fade" id="myModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">×</button>
				<h3>Settings</h3>
			</div>
			<div class="modal-body">
				<p>Here settings can be configured...</p>
			</div>
			<div class="modal-footer">
				<a href="#" class="btn" data-dismiss="modal">Close</a>
				<a href="#" class="btn btn-primary">Save changes</a>
			</div>
		</div>

		<footer>
			<p class="pull-left">&copy; <a href="http://usman.it" target="_blank">EduShare</a> 2012</p>
			<p class="pull-right">Powered by: <a href="http://usman.it/free-responsive-admin-template">EduShare</a></p>
		</footer>
		
	</div><!--/.fluid-container-->

	<!-- external javascript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->

	<!-- jQuery -->
	<script src="js/jquery-1.7.2.min.js"></script>
	<!-- jQuery UI -->
	<script src="js/jquery-ui-1.8.21.custom.min.js"></script>
	<!-- transition / effect library -->
	<script src="js/bootstrap-transition.js"></script>
	<!-- alert enhancer library -->
	<script src="js/bootstrap-alert.js"></script>
	<!-- modal / dialog library -->
	<script src="js/bootstrap-modal.js"></script>
	<!-- custom dropdown library -->
	<script src="js/bootstrap-dropdown.js"></script>
	<!-- scrolspy library -->
	<script src="js/bootstrap-scrollspy.js"></script>
	<!-- library for creating tabs -->
	<script src="js/bootstrap-tab.js"></script>
	<!-- library for advanced tooltip -->
	<script src="js/bootstrap-tooltip.js"></script>
	<!-- popover effect library -->
	<script src="js/bootstrap-popover.js"></script>
	<!-- button enhancer library -->
	<script src="js/bootstrap-button.js"></script>
	<!-- accordion library (optional, not used in demo) -->
	<script src="js/bootstrap-collapse.js"></script>
	<!-- carousel slideshow library (optional, not used in demo) -->
	<script src="js/bootstrap-carousel.js"></script>
	<!-- autocomplete library -->
	<script src="js/bootstrap-typeahead.js"></script>
	<!-- tour library -->
	<script src="js/bootstrap-tour.js"></script>
	<!-- library for cookie management -->
	<script src="js/jquery.cookie.js"></script>
	<!-- calander plugin -->
	<script src='js/fullcalendar.min.js'></script>
	<!-- data table plugin -->
	<script src='js/jquery.dataTables.min.js'></script>

	<!-- chart libraries start -->
	<script src="js/excanvas.js"></script>
	<script src="js/jquery.flot.min.js"></script>
	<script src="js/jquery.flot.pie.min.js"></script>
	<script src="js/jquery.flot.stack.js"></script>
	<script src="js/jquery.flot.resize.min.js"></script>
	<!-- chart libraries end -->

	<!-- select or dropdown enhancer -->
	<script src="js/jquery.chosen.min.js"></script>
	<!-- checkbox, radio, and file input styler -->
	<script src="js/jquery.uniform.min.js"></script>
	<!-- plugin for gallery image view -->
	<script src="js/jquery.colorbox.min.js"></script>
	<!-- rich text editor library -->
	<script src="js/jquery.cleditor.min.js"></script>
	<!-- notification plugin -->
	<script src="js/jquery.noty.js"></script>
	<!-- file manager library -->
	<script src="js/jquery.elfinder.min.js"></script>
	<!-- star rating plugin -->
	<script src="js/jquery.raty.min.js"></script>
	<!-- for iOS style toggle switch -->
	<script src="js/jquery.iphone.toggle.js"></script>
	<!-- autogrowing textarea plugin -->
	<script src="js/jquery.autogrow-textarea.js"></script>
	<!-- multiple file upload plugin -->
	<script src="js/jquery.uploadify-3.1.min.js"></script>
	<!-- history.js for cross-browser state change on ajax -->
	<script src="js/jquery.history.js"></script>
	<!-- application script for Charisma demo -->
	<script src="js/charisma.js"></script>
	
		
</body>

<%
    } else {
        out.println("<script>alert('Inicie sesión para poder ver esta página') </script>");
        out.println("<script>window.location = \"index.jsp\" </script>");
    }
%>
</html>
